package com.maidada.codesharebackend.enums;

import com.maidada.codesharebackend.constant.UserRoleConstant;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * @author maidada
 */
@Getter
@RequiredArgsConstructor
public enum UserRoleEnum {

    /**
     * 枚举
     */
    ADMIN(0, UserRoleConstant.ADMIN),
    USER(1, UserRoleConstant.USER);

    private final int code;
    private final String description;

    public static UserRoleEnum fromCode(int code) {
        for (UserRoleEnum role : UserRoleEnum.values()) {
            if (role.getCode() == code) {
                return role;
            }
        }
        return null;
    }
}